<template>
	<view style='padding:15px;'>
		<u--form :model="formData" ref="form1">
			<!-- <u-form-item label="机构" prop="depCodeParam" @click="showSelect = true;aNum=1;placeName='请输入机构'" labelWidth='150'>
				<u--input v-model="formData.depCodeParam" placeholder="请选择机构" readonly @change='changeInput'>
				</u--input>
			</u-form-item> -->
			<u-form-item label="企业名称" prop="coName" @click="showSelect = true;aNum=2;placeName='请输入企业名称'"
				labelWidth='150'>
				<u--input v-model="formData.coName" placeholder="请选择企业名称" readonly>
				</u--input>
			</u-form-item>
			<u-form-item label="询查人员" prop="pName" @click="showCheckSelect = true;aNum=3;placeName='请输入检查人员'"
				labelWidth='150'>
				<u--input v-model="formData.pName" placeholder="请选择检查人员" readonly>
				</u--input>
			</u-form-item>
			<u-form-item label="询查日期" prop="patrolTime" @click="showTime = true;" labelWidth='150'>
				<uni-datetime-picker type="datetime" v-model="formData.patrolTime" @change="confirm" />
			</u-form-item>
			<u-form-item label="当前节点" prop="statusName" @click="show = true;aNum=4" labelWidth='150'>
				<u--input v-model="statusName" placeholder="请选择当前节点" readonly>
				</u--input>
			</u-form-item>
		</u--form>
		<!-- 机构 /企业-->
		<qianziyuSelect :show="showSelect" type="radio" :dataLists="columnsCompany" :placeholder="placeName"
			@cancel="showSelect=false" @submit="confirmSelect" @search='search'>
		</qianziyuSelect>

		<!-- 人员 -->
		<qianziyuSelect :show="showCheckSelect" type="checkbox" :dataLists="columnsName" :placeholder="placeName"
			@cancel="showCheckSelect=false" @submit="confirmSelect" @search='search'>
		</qianziyuSelect>

		<!-- 节点 -->
		<qianziyuSelect :show="show" type="radio" :dataLists="columns" :placeholder="placeName" @cancel="show=false"
			:showSearch='false' @groupChange="confirmSelect" format="changeRadio">
		</qianziyuSelect>



		<u-button style='margin:15px auto;width:80%;' type="primary" size="large" @click="btnSearch()">查询</u-button>
		<u-button style='margin:15px auto;width:80%;' type="primary" size="large" @click="btnReset()">重置</u-button>
	</view>
</template>
<script>
	import qianziyuSelect from '@/components/qianziyu-select/qianziyu-select.vue'
	export default {
		components: {
			qianziyuSelect
		},
		data() {
			return {
				formData: {
					// depCodeParam: "",
					coName: "",
					pName: "",
					perId: "",
					ownerId: "",
					patrolTime: "",
					patrolStatusList: []
				},
				statusName: "",
				columnsCompany: [], //企业名称
				columnsName: [], //人员
				showSelect: false,
				showCheckSelect: false,
				// options: {},
				companyList: [], //企业
				nameList: [],
				aNum: '', //区分是哪个下拉
				placeName: "",
				showTime: false,
				show: false,
				columns: [{
						id: 1,
						name: "询查中",
					},
					{
						id: 2,
						name: "已询查",
					},
					{
						id: 4,
						name: "整改中",
					},
					{
						id: 5,
						name: "已整改",
					},
					{
						id: 6,
						name: "待完结",
					},
					{
						id: 7,
						name: "已完结",
					},
				],
			}
		},
		// onLoad(option) {
		// 	this.options = option
		// },
		mounted() {

			this.$api.findOwner().then((res) => {
				res.data.data.forEach((item) => {
					this.columnsCompany.push({
						id: item.ownerId,
						name: item.ownerName,
					});
					this.companyList.push({
						id: item.ownerId,
						name: item.ownerName,
					})
				});
			});

			this.$api.getDeptUserList(this.$store.state.userInfo.dept_id, this.$store.state.userInfo.tenant_id).then(
				res => {
					if (res.data.data.length == 0) {
						this.columnsName = []
						this.nameList = []
					} else {
						res.data.data.forEach((item) => {
							this.columnsName.push({
								id: item.id,
								name: item.name,
							});

							this.nameList.push({
								id: item.id,
								name: item.name,
							});
						});
					}
				})
		},
		methods: {
			cancelPicker() {
				this.showTime = false
			},
			// 选择日期确定
			confirm(e) {
				this.formData.patrolTime = e
				this.showTime = false
			},
			// 查询
			btnSearch() {
				if (!this.statusName) {
					uni.showToast({
						title: '请选择当前节点！！',
						icon: 'none',
						duration: 1000
					});
					return
				}
				const searchList = {
					...this.formData
				}
				delete searchList.coName
				delete searchList.pName
				if (searchList.patrolTime.length <= 12) {
					searchList.patrolTime = searchList.patrolTime.replace(/^\s*|\s*$/g, "")
				}

				this.$goBack('./patrolName?formSearch=' + encodeURIComponent(JSON.stringify(searchList)),
					5);
			},

			// 人员/企业 确定
			confirmSelect(e) {
				this.formData.patrolStatusList = []
				// if (this.aNum == 1) {
				// 	this.formData.depCodeParam = e.name
				// 	this.formSearch.depCodeParam = e.id
				// }
				// 企业
				if (this.aNum == 2) {
					this.formData.coName = e.name
					this.formData.ownerId = e.id
					this.showSelect = false
				}
				// 人员
				if (this.aNum == 3) {
					e.map(item => {
						this.formData.pName += item.name + ','
						this.formData.perId += item.id + ','

					})
					this.formData.pName = this.formData.pName.substring(0, this.formData.pName.lastIndexOf(
						','));
					this.formData.perId = this.formData.perId.substring(0, this.formData.perId.lastIndexOf(
						','));
					this.showCheckSelect = false
				}

				if (this.aNum == 4) {
					this.statusName = e.name
					this.formData.patrolStatusList.push(e.id)
					this.show = false
				}

			},

			// 搜索查询
			search(keyword) {
				const aArr = ['columns', 'columnsCompany', 'columnsName']
				let arrList = []
				if (keyword == '') {
					if (this.aNum == 2) {
						this.columnsCompany = this.companyList
					} else {
						this.columnsName = this.nameList
					}
				} else {
					this[aArr[this.aNum - 1]].forEach(item => {
						if (item.name.indexOf(keyword) != -1) {
							arrList.push(item)
						}
					})
					this[aArr[this.aNum - 1]] = arrList
				}

			},

			// 重置
			btnReset() {
				this.$refs.form1.resetFields()
				this.statusName = ""
			}


		}
	}
</script>

<style lang="scss" scoped>
</style>
